package com.coolwen.spring.ioc.java;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

/**
 * @author CoolWen
 * @version 2020-03-04 14:32
 */
@Component
public class Knight {
    private String username;
    private Weapon weapon;

    public Knight() {
    }

    public Knight(String username, Weapon weapon) {
        this.username = username;
        this.weapon = weapon;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Weapon getWeapon() {
        return weapon;
    }

    @Autowired
    @Qualifier("knife")
    public void setWeapon(Weapon weapon) {
        this.weapon = weapon;
    }

    public void fight() {
        System.out.println(username + "开始攻击了");
        weapon.attck();
    }
}
